﻿/*
COPYRIGHT (C) 2010 EPISERVER AB

THIS FILE IS PART OF PROPERTY PACK FOR EPISERVER CMS.
DYNAMIC CONTENT CONTRIB FOR EPISERVER CMS IS FREE SOFTWARE: YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE VERSION v2.1 AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.

PROPERTY PACK FOR EPISERVER CMS IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE ALONG WITH PROPERTY PACK FOR EPISERVER CMS. IF NOT, SEE <HTTP://WWW.GNU.ORG/LICENSES/>.
*/
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EPiServer.Core.PropertySettings;
using System.Collections.Generic;
using EPiServer.UI.WebControls;

namespace EPiServer.Research.Properties
{
    /// <summary>
    /// The UI for the Settings for Properties
    /// </summary>
    public class ValidatedStringSettingsUI : PropertySettingsControlBase
    {
        protected TextBox regexTxt;
        protected TextBox errorTxt;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Controls.Add(new Label() { Text="Regular expression to validate against"});
            Controls.Add(new LiteralControl("<br/>"));
            regexTxt = new TextBox();
            Controls.Add(regexTxt);
            Controls.Add(new LiteralControl("<br/><br/>"));
            Controls.Add(new Label() { Text = "Error message to show if text is invalid" });
            Controls.Add(new LiteralControl("<br/>"));
            errorTxt = new TextBox();
            Controls.Add(errorTxt);

        }

        public override void LoadSettingsUI(IPropertySettings settings)
        {
            EnsureChildControls();
            regexTxt.Text = (settings as ValidatedStringSettings).RegularExpression;
            errorTxt.Text = (settings as ValidatedStringSettings).ErrorMessage;
        }

        public override void UpdateSettings(IPropertySettings settings)
        {
            EnsureChildControls();
            (settings as ValidatedStringSettings).RegularExpression = regexTxt.Text;
            (settings as ValidatedStringSettings).ErrorMessage = errorTxt.Text;
        }
    }
}
